// 获取文章相关接口

import type { ArticleListParams, ArticleListRes, ChannelRes, PublishArticleParams } from "@/types/article"
import { request } from "@/utils/request"

// 获取频道列表
export const getChannelsAPI = () => {
  return request<ChannelRes>('/v1_0/channels')
}

// 获取文章列表
export const getArticleListAPI = (params: ArticleListParams) => {
  return request<ArticleListRes>('/v1_0/mp/articles', 'GET', params)
}
// 删除文章
export const delArticleAPI = (id: number) => {
  return request(`/v1_0/mp/articles/${id}`, 'DELETE')
}

// 图片上传
export const uploadImageAPI = (file :FormData) => {
  return request<{url :string}>('/v1_0/upload', 'POST', file)
}

// 文章发布
export const pubArticleAPI = (draft:boolean, data: PublishArticleParams) => {
  return request(`/v1_0/mp/articles/`, 'POST', data,{   
      draft
  })
}

// 获取文章详情
export const getArticleDetailAPI = (id: string) => {
  return request<PublishArticleParams>(`/v1_0/mp/articles/${id}`)
}

// 修改文章
export const updateArticleAPI = (id: string, draft:boolean , data: PublishArticleParams) => {
  return request(`/v1_0/mp/articles/${id}`, 'PUT', data,{    
      draft 
  })
}